#include <QCoreApplication>
#include <event2/event.h>
#include <event2/listener.h>
#include <iostream>
#include <signal.h>

void listen_cb(struct evconnlistener *e, evutil_socket_t s, struct sockaddr *a, int socklen, void *arg){
    std::cout << "listen_cb" << std::endl;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    if(signal(SIGPIPE,SIG_IGN) == SIG_ERR){
        return -1;
    }
    std::cout << "test server\n";
    event_base* base = event_base_new();
    if(base){
       std::cout << "event_base_new success\n";
    }
    sockaddr_in sin;
    memset(&sin,0,sizeof(sin));
    sin.sin_family = AF_INET;
    sin.sin_port = htons(6666);
    evconnlistener* ev = evconnlistener_new_bind(base,listen_cb,base,LEV_OPT_REUSEABLE | LEV_OPT_CLOSE_ON_FREE,
                                                 10,(sockaddr*)&sin,sizeof(sin));



    event_base_dispatch(base);
    if(ev)
        evconnlistener_free(ev);
    if(base)
        event_base_free(base);

    return a.exec();
}
